package units
{
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class Projectile_Path extends MovieClip
	{
		var game_handler:GameHandler;
		var died = false;
		var source_unit,target_unit;
		public function Projectile_Path(gH:GameHandler,sU,tU)
		{
			game_handler=gH;
			game_handler.projectiles.push(this);
			game_handler.addChild(this);
			
			source_unit = sU;
			target_unit = tU;
			
			this.x = source_unit.x;
			this.y = source_unit.y;
			
			generate_projectile();
		}
		public function run(){
			this.alpha -= .1;
			if(this.alpha <= 0)
				die();
		}
		
		public function generate_projectile(){
			this.graphics.lineStyle(2,0xCCCC00);
			this.graphics.lineTo(target_unit.x-this.x,target_unit.y-this.y);
		}
		
		public function die(){
			if(died)
				return;
			died = true;
			var my_spot=-1;
			for(var i:int = 0; i < game_handler.projectiles.length; i++)
				if(game_handler.projectiles[i] == this)
					my_spot = i;
			if(my_spot != -1)
				game_handler.projectiles.splice(my_spot,1);
			game_handler.removeChild(this);
		}
	}
}